<?php

namespace Xin\Coze\Providers;

class BotProvider extends AbstractProvider
{
	/**
	 * 获取智能体配置
	 * @param string $botId
	 * @param array $options
	 * @return array
	 */
	public function config(string $botId, array $options = [])
	{
		return $this->coze->httpGet("/v1/bot/get_online_info", [
			'bot_id' => $botId,
		], $options);
	}

	/**
	 * 创建智能体
	 * @param string $spaceId
	 * @param string $name
	 * @param array{
	 *     description?:string,
	 *     icon_file_id?:string,
	 * } $data
	 * @param array $options
	 * @return array
	 */
	public function create(string $spaceId, string $name, array $data = [], array $options = [])
	{
		$data = array_merge($data, [
			'space_id' => $spaceId,
			'name' => $name,
		]);

		return $this->coze->httpPost('/v1/bot/create', $data, $options);
	}

	/**
	 * 更新智能体
	 * @param string $botId
	 * @param array{
	 *     name?:string,
	 *     description?:string,
	 *     icon_file_id?:string,
	 * } $data
	 * @param array $options
	 * @return array
	 */
	public function update(string $botId, array $data = [], array $options = [])
	{
		$data = array_merge($data, [
			'bot_id' => $botId,
		]);
		return $this->coze->httpPut("/v1/bot/update", $data, $options);
	}

	/**
	 * 发布智能体
	 * @param string $botId
	 * @param array $connectorIds
	 * @param array $options
	 * @return array
	 */
	public function publish(string $botId, array $connectorIds, array $options = [])
	{
		return $this->coze->httpPost("/v1/bot/publish", [
			'bot_id' => $botId,
			'connector_ids' => $connectorIds,
		], $options);
	}

	/**
	 * 获取智能体列表
	 * @param string $spaceId
	 * @param int $page
	 * @param int $pageSize
	 * @param array $options
	 * @return array
	 */
	public function list(string $spaceId, int $page = 1, int $pageSize = 10, array $options = [])
	{
		return $this->coze->httpGet('/v1/space/published_bots_list', [
			'space_id' => $spaceId,
			'page_index' => $page,
			'page_size' => $pageSize,
		], $options);
	}
}
